package edu.mq.itec814

import scala.actors.Actor
import scala.actors.Actor._

class MessageReceiver (sender : MessageSender) extends Actor {

  private def factorial (n : Int) : Int = {
	  if (n==0) 
	  	1 
	  else {
			n * factorial(n-1)
	  }
  }
  
  private def compute (data : Data) : Int =  {
    Thread.sleep(100)	// Required to simulate something that is actually computationally intensive
    factorial (data.a + data.b)
  }
  
  def act () {
    loop {
    	react {
    		case data : Data =>
    			val computedVal = compute (data)
    			sender ! computedVal
    		case Stop =>
    			sender ! Stop
    			exit ()
    	}
    }
    
  }
  
}